package Linux五种IO模型;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Date;

/**
 * @author coderFu
 * @create 2022/3/5
 * socket 客户端
 */
public class SocketClient {

    public static void main(String[] args) {

        // 创建多个客户端模拟链接到服务端
        new Thread(()->{

            try{
                Socket  socket = new Socket("127.0.0.1",9999);
                while (true){
                    // 模拟每两秒钟向服务端发送消息
                    socket.getOutputStream().write((new Date()+": hello world").getBytes());
                    Thread.sleep(2000);
                }
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }

        },"线程1").start();
    }
}
